package top.maof.book.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.maof.book.model.History;

import java.util.List;

@Mapper
public interface HistoryMapper extends BaseMapper<History> {
    // 个人历史
    @Select("select id,user_id,book_id,contents_id,chapter_id,ip,insert_date from history where user_id = #{userId}")
    List<History> findHistoriesByUser(@Param("userId") Integer userId);

    //小说的点击量
    @Select("select count(id) from history where book_id = #{bookId}")
    Integer clickCount(@Param("bookId") int bookId);

    @Insert("insert into history (id,user_id,book_id,contents_id,chapter_id,ip,insert_date) " +
            "values (#{id},#{userId},#{bookId},#{contentsId},#{chapterId},#{ip},#{insertDate})")
    int add(History history);
}
